package com.cat.twoPointerTechnique;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-mountain-in-array/
 * @create 2025/8/8 14:52
 * @since JDK17
 */

public class Solution23 {
    public int longestMountain(int[] arr) {
        if (arr.length < 3) {
            return 0;
        }
        int n = arr.length - 1, ans = 0;
        for (int i = 0; i < n; ) {
            if (arr[i] == arr[i + 1]) { // 相等了，不可能是山脉了
                i++;
                continue;
            }
            int start = i++;
            while (i < n && arr[i] < arr[i + 1]) {
                i++;
            }
            while (i < n && arr[i] > arr[i + 1]) {
                i++;
            }
            ans = Math.max(ans, i - start + 1);
        }

        return ans;
    }
}
